/*
Date:20220124 14:00P<
key:1。本道题的收获都围绕multiset(可重复有序集合)
2.erase删除与elem相等的所有元素，返回被移除的元素个数。所以想删除一个某个值的元素，要先通过find，然后erase指针。
*/
class StockPrice {
public:
    unordered_map<int,int>m;
    multiset<int> prices;
    int real_timestamp;
    StockPrice() {this->real_timestamp=INT_MIN;
    }
    void update(int timestamp, int price) 
    {
    auto tmp=this->m.find(timestamp);
if(tmp==m.end())
{
    //更新
    real_timestamp=max(timestamp,real_timestamp);
    m[timestamp]=price;
   
}else{
    auto it=prices.find(tmp->second);
    prices.erase(it);
    tmp->second=price;
    }
prices.emplace(price);
    }
    
    int current() {
return m[real_timestamp];
    }
    
    int maximum() {
return *prices.rbegin();
    }
    
    int minimum() {
return *prices.begin();
    }
};

/**
 * Your StockPrice object will be instantiated and called as such:
 * StockPrice* obj = new StockPrice();
 * obj->update(timestamp,price);
 * int param_2 = obj->current();
 * int param_3 = obj->maximum();
 * int param_4 = obj->minimum();
 */